package com.xr.security;

import java.util.ArrayList;
import java.util.List;

import org.marmot.security.domain.Role;
import org.marmot.security.domain.User;
import org.marmot.security.service.impl.HibernateUserRoleService;

import com.bstek.dorado.common.DoradoContext;

public class DemoUserService extends HibernateUserRoleService {

	public Role getRole(String id) {
		Role role = new Role();
		if (id.equals("ROLE_ADMIN")){
			role.setId("ROLE_ADMIN");
			role.setName("ROLE_ADMIN");
			role.setLabel("ROLE_ADMIN");
			role.setDescn("ROLE_ADMIN");
		}
		else if (id.equals("ROLE_GUEST")){
			role = new Role();
			role.setId("ROLE_GUEST");
			role.setName("ROLE_GUEST");
			role.setLabel("ROLE_GUEST");
			role.setDescn("ROLE_GUEST");
		}
		return role;
	}

	public List getAllRoles() {
		List list = new ArrayList();
		Role role = new Role();
		role.setId("ROLE_ADMIN");
		role.setName("ROLE_ADMIN");
		role.setLabel("ROLE_ADMIN");
		role.setDescn("ROLE_ADMIN");
		list.add(role);
		
		role = new Role();
		role.setId("ROLE_GUEST");
		role.setName("ROLE_GUEST");
		role.setLabel("ROLE_GUEST");
		role.setDescn("ROLE_GUEST");
		list.add(role);	
		
		return list;
	}

	public List getRolesByUser(User user, boolean loadProxy) {
		List list = new ArrayList();
		Role role = new Role();
		role.setId("ROLE_ADMIN");
		role.setName("ROLE_ADMIN");
		role.setLabel("ROLE_ADMIN");
		role.setDescn("ROLE_ADMIN");
		list.add(role);
		
		return list;
	}

	public User getUserByAccount(String account) {
		DoradoContext conext = DoradoContext.getContext();
		com.xr.system.User appUser = (com.xr.system.User)conext.getAttribute(DoradoContext.SESSION,
				"User");
		User user = new User();
		user.setId(appUser.getUserName());
		user.setLoginid("admin");
		user.setStatusFlag(true);
		user.setName("admin");
		user.setPasswd("1");
		
		return user;
	}

}
